package com.junqi.media.controller;
import com.junqi.media.service.HlsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * hls接口
 *
 */
@Slf4j
@RestController
@RequestMapping("/hls")
public class HlsController {

	@Autowired
	HlsService hlsService;

	/**
	 * hls播放接口 获取ts文件
	 * roomId 房间id
	 * tsName 模版名字
	 * @throws IOException
	 */
	@GetMapping("/ts")
	public void getts(HttpServletResponse response, @RequestParam("roomId") String roomId,
					  @RequestParam("tsName") String tsName) throws IOException {
		hlsService.getTsFile(response, roomId, tsName);
	}


	/**
	 * hls播放接口 获取m3u8文件
	 * roomId 房间id
	 * @throws IOException
	 */
	@GetMapping("/m3u8")
	public void video(@RequestParam("roomId") String roomId, HttpServletResponse response)
			throws IOException {
		hlsService.video(roomId, response);
	}

}
